import type { ApiResponse} from '@/types/basetypes';
import request from '@/utils/request'
import type {Files, files, UploadFileInfoType, UploadUrls} from "@/types/files/types.ts";

/**
 * 根据 md5 检查文件是否上传，若上传一半，则返回已上传的文件序号 listParts
 * @param md5
 * @returns
 */
export const _checkFileByMd5 = async (params:  { md5: string }) :Promise<ApiResponse<UploadFileInfoType>> =>{
  const { md5 } = params;
  return request({
    url: `files/multipart/check/${md5}`,
    method: 'GET'
  });
}

/**
 * 根据文件信息初始化分片上传地址
 * @param params
 */
export const _initMultPartFile = async (params: UploadFileInfoType): Promise<ApiResponse<UploadUrls>> => {
  return request({
    url: 'files/multipart/init',
    method: 'POST',
    data: params,
  });
}

/**
 * 合并文件
 * @param md5
 * @returns
 */
export const _mergeFileByMd5 = async (params:  { md5: string }): Promise<ApiResponse<UploadUrls>> => {
  const { md5 } = params;
  return request({
    url: `files/multipart/merge/${md5}`,
    method: 'POST'
  });
}
/**
 * 合并文件
 * @returns
 */
export const _list = async () :Promise<ApiResponse<Files>> =>{
  return request({
    url: `files/list`,
    method: 'GET'
  });
}

